package com.qf.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zhaojian
 */
@RestController
@RefreshScope  //刷新配置信息
@RequestMapping("/provider")
public class TestProviderController {

//    @Value("${version}")
//    private String version;

    @Value("${text}")
    private String text;

    //给资源取一个名称
    @SentinelResource(value = "/yyyyy",blockHandler = "blockException",fallback = "fallback")
    @RequestMapping("/hello")
    public String test(String name, String sex) {
        System.out.println("name:" + name);
//        try {
//            Thread.sleep(1500);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
        return "欢迎来到千锋教育, 北科校区学习java编程! text::" + text;
    }

    public String blockException(String name, String sex, BlockException e) {
        e.printStackTrace();
        return "限流了!!!!";
    }

    public String fallback(String name, String sex, Throwable e) {
        e.printStackTrace();
        return "出现异常了!!!!";
    }
}
